/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package stablemarriage;

import java.io.*;
import java.util.*;
import java.util.Scanner;

/**
 *
 * @author Jacob
 */
public class StableMarriage {

    Stack<Integer>[] preferencesMen;
    int[][] preferencesWomen;
    Stack<Integer> freeMen;
    int[] engagedWomen;
    String[] maleNames, femaleNames;
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        StableMarriage problem = new StableMarriage();
        problem.readInput("stable-marriage-friends.in");
        System.out.println(problem.solve());
    }
    
    private void readInput(String filename) {
        try {
            Scanner sc = new Scanner(new File(filename));
            String line = sc.nextLine();
            while (line.startsWith("#"))
                line = sc.nextLine();
            
            int n = Integer.parseInt(line.substring(2));
            preferencesMen = new Stack[n + 1];
            preferencesWomen = new int[n + 1][n + 1];
            freeMen = new Stack<>();
            engagedWomen = new int[n + 1];
            maleNames = new String[n + 1];
            femaleNames = new String[n + 1];
            
            while (sc.hasNext()) {
                for (int i = 1; i <= n * 2; i++) {
                    sc.skip("[0-9]+ ");
                    if (i % 2 == 1) {
                        maleNames[(i + 1) / 2] = sc.nextLine();
                        freeMen.add((i + 1) / 2);
                    } else
                        femaleNames[i / 2] = sc.nextLine();
                }
                sc.nextLine();
                for (int i = 1; i <= n * 2; i++) {
                    sc.skip("[0-9]+:");
                    if (i % 2 == 1) {
                        preferencesMen[(i + 1) / 2] = new Stack<>();
                        for (int j = 0; j < n; j++)
                            preferencesMen[(i + 1) / 2].add(sc.nextInt() / 2);
                    } else {
                        for (int j = 0; j < n; j++)
                            preferencesWomen[i / 2][(sc.nextInt() + 1) / 2] = j;
                    }
                    sc.nextLine();
                }
            }
        } catch (IOException e) {
            System.out.println("Could not find the specified file.");
        }
    }
    
    private String solve() {
        // TODO
        return "done";
    }
}
